package com.user.server;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.user.dao.UserMapper;
import com.user.entity.User;
import com.user.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public PageInfo<User> selects(User user, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list = userMapper.selects(user);
        return new PageInfo<>(list);
    }

    @Override
    public boolean save(User user) {
        if(user.getId()==null){
            String pwd = Md5Util.md5Encoding(user.getPwd());
            user.setPwd(pwd);
            return userMapper.insert(user)>0;
        }
        return userMapper.update(user)>0;
    }

    @Override
    public boolean del(String ids) {
        return userMapper.del(ids)>0;
    }

    @Override
    public User login(User user) {
        String pwd = Md5Util.md5Encoding(user.getPwd());
        user.setPwd(pwd);
        return userMapper.login(user);
    }

}
